# coding=utf-8
import json
import sys
import time

import allure
import pytest
from jsonpath import jsonpath
from common.assert_operator import *
from common.db import *
# sys.path.append("..")
from common.read_yaml import *
from common.utils import Utils

string_assert = string_assert() # 字符串校验类
pact = Pact() # 契约校验类
execute_sql = sql() # sql集合
utils = Utils()
data = ReadYaml_By_Root_Dict("case/01_initiate_process_test/01_2_CreateProcess_Check.yml").get_yaml_data()  # 读取数据


@allure.feature('发起校验场景')  # 测试报告显示测试功能
class Test_01_2_CreateProcess_Check():

    # 获取yml文件中[发起校验]的数据参数
    initiate_process_params = data['发起校验']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(initiate_process_params,"$[*][0]")
    @pytest.mark.parametrize("title, param, expect", initiate_process_params,ids=ids_list)
    def test_CreateProcess_Check(self, user_login, title, param, expect):
        utils.mark_skip_case(param,'bug')  # 存在需要跳过的用例
        Logger.info("*************** {}开始执行用例 ***************".format(title))
        allure.dynamic.description(f"{param['description']}")  # # 动态解析用例描述在测试报告中展示
        user = param['user']   # 登录用户
        main = user_login.goto_Create_Process(user)
        # 新建流程
        open_process = main.process_create(param['module_name'])
        # 发起前重载表单
        reload_resp = main.form_data_reload(param,open_process)
        # 测试重载接口
        Expected = {"code":1,"data":{"main":[],"children":[],"file_control":[],"form_data_md5":None,"relation_process":[]},"message":"","detailMessage":"","success":1}
        dict_assert(Expected,reload_resp.json())
        # 发起流程返回步骤路径
        steps_resp = main.get_initiate_steps(param,open_process,opinion='发起流程')
        # 确认路径校验
        steps_info = utils.pack_confirm_steps_field(steps_resp.json())
        dict_assert(expect['确认路径校验'],steps_info)
        # 发起流程，并校验
        response = main.initiate_submit(param, steps_resp, '发起流程')
        string_assert.eq(response.status_code, 200) # 校验状态码
        dict_assert(expect['发起响应校验'],response.json())  # 校验返回内容
        Logger.info("*************** {}结束执行用例 ***************".format(title))



if __name__=="__main__":
    pytest.main(['-s',r'D:\PycharmProjects\ProcessCenter_Api_Autotest\case\test_01_initiate_process\01_1_CreateProcess_Confirm_test.py'])